﻿@{
    ViewData["Title"] = "创建新文档";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model Mango.Web.ViewModels.DocsEditViewModel
<div class="row" style="margin-top:20px;">
    <form class="form-horizontal" method="post" id="formData">
        <div class="input-group mb-3">
            <div class="input-group-prepend">
                <span class="input-group-text" id="basic-addon1">文档短标题:</span>
            </div>
            <input type="text" class="form-control" id="ShortTitle" name="ShortTitle" placeholder="填写一个更简洁意骇的标题" value="@Model.DocsData.ShortTitle">
        </div>
        <div class="input-group mb-3">
            <div class="input-group-prepend">
                <span class="input-group-text" id="basic-addon1">文档标题:</span>
            </div>
            <input type="text" class="form-control" id="Title" name="Title" placeholder="你可以取一个简洁的标题..."  value="@Model.DocsData.Title">
        </div>

        <div class="form-group">
            <textarea style="height:360px;width:800px;" id="Contents" name="Contents" placeholder="输入你想发布的内容...">@Html.Raw(Model.DocsData.Contents)</textarea>
        </div>

        <div class="form-group" style="margin-top:15px;">
            <input type="hidden" id="DocsId" name="DocsId" value="@ViewData["DocsId"]" />
            <button type="button" id="btn_Post" class="btn btn-success">马上发布</button>
        </div>
        <div class="form-group">
            <span class="text">温馨提示:请勿发布人身攻击以及一切违法的图片以及文字.</span>
        </div>
    </form>
</div>
@section Scripts{

    <script src="~/lib/jquery/jquery.validator.min.js"></script>
    <script src="~/lib/jquery/jquery.form.js"></script>

    <script src="~/lib/tinymce/tinymce.min.js"></script>
    <script src="~/lib/tinymce/langs/zh_CN.js"></script>

    <script src="~/lib/tinymce/plugins/codesample/plugin.min.js"></script>
    <script src="~/lib/tinymce/plugins/link/plugin.min.js"></script>

    <script src="~/lib/tinymce/plugins/image/plugin.min.js"></script>

    <script src="~/lib/tinymce/plugins/imageupload/upyun.plugin.min.js"></script>
    <script>
        tinymce.init({
            selector: '#Contents',
            language: "zh_CN",
            themes: "modern",
            menubar: false,
            toolbar: [
                'removeformat | bold italic underline strikethrough | codesample link imageupload | alignleft aligncenter alignright',
            ],
            plugins: [
                'codesample', 'link', 'image', 'imageupload'
            ],
            upload_image_url: 'https://v0.api.upyun.com/51core',
            file_server_url: 'https://file.51core.net'
        });

    </script>
    <script type="text/javascript">

        $("#btn_Post").click(function () {
            $("#Contents").val(tinymce.get('Contents').getContent());
            //加载验证
            var config = new Array();

            config.push({
                id: $("#ShortTitle"),
                required: { tip: '请输入文档短标题' },
                length: { min: 1, max: 30 }
            });
            config.push({
                id: $("#Title"),
                required: { tip: '请输入文档标题' },
                length: { min: 1, max: 80 }
            });
            config.push({
                id: $("#Contents"),
                required: { tip: '请输入文档内容' },
                length: { min: 10, max: 60000 }
            });

            var v = $.Validator({
                items: config
            });
            if (v.Create()) {
                var tipIndex = layer.load(2);
                $("#formData").ajaxSubmit({
                    url: '/user/MyDocs/EditDocs',
                    success: function (result) {
                        if (result == "ok") {
                            layer.msg("发布成功", function () {
                                layer.close(tipIndex);
                                window.location.href = '/docs/read/@(ViewContext.HttpContext.Request.Query["themeId"])/@ViewData["DocsId"]';
                            });
                        }
                        else {
                            layer.close(tipIndex);
                            layer.msg(result);
                        }
                    }
                });
            }
            else {
                return false;
            }
        });
    </script>
}

